<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    #list {
      height: 150px;
      background-color: skyblue;
      overflow: auto;
      width: 200px;
    }
    .item {
      height: 30px;
    }
  </style>
  <body>
    <div id="list">
      <div></div>
    </div>
    <script>
      let list = document.getElementById("list");
      let i = 1;
      setInterval(() => {
        let div = document.createElement("div");
        div.className = "item";
        div.innerHTML = i;
        let prevheight = list.scrollHeight;
        let prevTop = list.scrollTop;
        list.insertBefore(div, list.firstChild);
        let nowheight = list.scrollHeight;
        let cha = nowheight - prevheight;
        console.log(list.scrollTop, cha);
        list.scrollTop = prevTop + cha;
        console.log(list.scrollTop);
        i++;
      }, 3000);
      list.onscroll = function () {
        console.log(list.scrollTop);
      };
    </script>
  </body>
</html>
